﻿'-------------------------------------------------------------------------------
'Developer: Ivan Tamurejo
'-------------------------------------------------------------------------------
'This class allows us to obtain registration of an ActiveX as the name, CLSID, 
'major and minor version component values.
'-------------------------------------------------------------------------------

Option Strict Off

Imports System.IO

Public Class Component

#Region "Private variables"

    Private oTypeLib As Object
    Private IsDisposed As Boolean

#End Region

#Region "Procedures -New- and -Finalize-"

    Sub New(ByVal ComponentFilePath As String)

        If Not File.Exists(ComponentFilePath) Then

            Throw New Exception("> Component file does not valid or not exist.")

        End If

        Try
            oTypeLib = CreateObject("TLI.TypeLibInfo")
            If Not oTypeLib Is Nothing Then

                oTypeLib.ContainingFile = ComponentFilePath

            End If
        Catch
            oTypeLib = Nothing
        End Try

    End Sub

    Public Sub Dispose()

        Finalize()

    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()

        If Not IsDisposed Then

            oTypeLib = Nothing

            IsDisposed = True

        End If

    End Sub

#End Region

#Region "Functions to retrieve values of the component as the name, CLSID, major and minor version"

    Public Function GetCLSID() As String


        If Not oTypeLib Is Nothing Then

            Return oTypeLib.GUID

        End If

        Return ""

    End Function

    Public Function GetName() As String


        If Not oTypeLib Is Nothing Then

            Return oTypeLib.Name

        End If

        Return ""

    End Function

    Public Function GetLCID() As String


        If Not oTypeLib Is Nothing Then

            Return oTypeLib.LCID

        End If

        Return ""

    End Function

    Public Function GetMajorVersion() As String


        If Not oTypeLib Is Nothing Then

            Return oTypeLib.MajorVersion

        End If

        Return ""

    End Function

    Public Function GetMinorVersion() As String


        If Not oTypeLib Is Nothing Then

            Return oTypeLib.MinorVersion

        End If

        Return ""

    End Function

#End Region

End Class
